package me.friwi.jcefsampleapp;

import me.friwi.jcefmaven.CefBuildInfo;
import me.friwi.jcefmaven.EnumPlatform;
import me.friwi.jcefmaven.UnsupportedPlatformException;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Locale;

/**
 * Just a small class that assists users in generating test reports.
 * You can ignore this, it is not really part of the example.
 *
 * @author Fritz Windisch
 */
public class TestReportGenerator {
    public static void print(String[] args) throws IOException, UnsupportedPlatformException {
        System.out.println("Please consider reporting back whether this build worked on your platform or not.");
        System.out.println("To report back, follow these 3 (1/2) easy steps (it will take ~1 minute):");
        System.out.println("    1) Check if everything is working");
        System.out.println("    2) Go to https://github.com/jcefmaven/jcefmaven/issues/new?assignees=&labels=test+report&template=report_artifact_working.md&title=%5BTR%5D+Test+report");
        System.out.println("    3) Paste the following report as the issue text. Replace <Y/N> under \"Working?\" with Y or N.");
        System.out.println("    4) If the build did not work, make sure to add debug info like console output or screenshots below.");
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        System.out.println("Test report generated by JCefSampleApp");
        System.out.println("**Tag**");
        System.out.println("{mvn_version}");
        System.out.println("");
        System.out.println("**OS (linux/windows/macosx)**");
        System.out.println(EnumPlatform.getCurrentPlatform().getOs().name().toLowerCase(Locale.ENGLISH));
        System.out.println("");
        System.out.println("**Version/Flavor (e.g. Ubuntu 20.04, Windows 10, Big Sur)**");
        if(EnumPlatform.getCurrentPlatform().getOs().isLinux()){
            try {
                String version = (new BufferedReader(new InputStreamReader((new ProcessBuilder("lsb_release", "-ds")).start().getInputStream()))).readLine();
                System.out.println(version+" ("+System.getProperty("os.version")+")");
            }catch (Exception e){
                System.out.println(System.getProperty("os.version"));
            }
        }else if(EnumPlatform.getCurrentPlatform().getOs().isMacOSX()){
            try {
                String name = (new BufferedReader(new InputStreamReader((new ProcessBuilder("sw_vers", "-productName")).start().getInputStream()))).readLine();
                String version = (new BufferedReader(new InputStreamReader((new ProcessBuilder("sw_vers", "-productVersion")).start().getInputStream()))).readLine();
                System.out.println(name.trim()+" "+version.trim()+" ("+System.getProperty("os.version")+")");
            }catch (Exception e){
                System.out.println(System.getProperty("os.version"));
            }
        }else{
            System.out.println(System.getProperty("os.name")+" "+System.getProperty("os.version"));
        }
        System.out.println("");
        System.out.println("**Arch (amd64/i386/arm64/arm)**");
        System.out.println(EnumPlatform.getCurrentPlatform().getIdentifier().split("-")[1]);
        System.out.println("");
        System.out.println("**Report as working? (Y/N)**");
        System.out.println("<Y/N>");
        System.out.println("");
        System.out.println("**Did you test with the official sample app? (Y/N)**");
        System.out.println("Y");
        System.out.println("");
        System.out.println("**Additional information**");
        if(args.length!=0){
            System.out.println("Passed command line arguments: "+Arrays.toString(args)+"\n");
        }
        System.out.println("Your additional info and additional text here, if you want to tell us something.");
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    }
}
